home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DRIVES.SWG / 0047_Is DISK Ready ??.pas < prev    next >
Pascal/Delphi Source File  |  1993-10-28  |  3KB  |  117 lines

  1. {===========================================================================
  2. Date: 10-03-93 (00:14)
  3. From: BRIAN PAPE
  4. Subj: disk ready
  5. ---------------------------------------------------------------------------
  6. Does anyone know if there is any better (and FASTER!) way to tell if a
  7. disk drive is ready?  I wrote a function yesterday to do that by calling
  8. the BIOS Read Track interrupt.  The only problem is that it has to
  9. actually read from the disk, and it is rather slow, especially on slower
  10. computers.
  11.  
  12. Here is my code: }
  13.  
  14. { NOTE :
  15.  
  16.           Added a BOOLEAN function and added Reset DRIVE  GDAVIS 10/15/93}
  17.  
  18. USES CRT;
  19.  
  20. VAR
  21.    Buf : ARRAY[0..512] OF BYTE;  { Buffer MUST be outside }
  22.  
  23. function diskstatus(drive:byte):byte; assembler;  { drive is A=0, B=1 etc}
  24. asm
  25.   cmp  drive,26
  26.   jb   @driveok
  27.   mov  drive,0   { if drive isn't between 0 and 25, make it 0 (for A:) }
  28.   @driveok:
  29.  
  30.   mov  ax, seg buf
  31.   mov  es, ax
  32.   mov  bx, offset buf
  33.  
  34.   mov  ah, 02      { read disk sectors }
  35.   mov  al, 1       { number of sectors to transfer }
  36.   mov  ch, 1       { track number }
  37.   mov  cl, 1       { sector number }
  38.   mov  dh, 1       { head number }
  39.   mov  dl, drive   { drive number (0=A, 3=C, or 80h=C, 81h=D) }
  40.   int  13h
  41.  
  42.   mov  bl,0    { assume drive is ready }
  43.   jnc  @done   { carry set if unsuccessfull (i.e. disk is not ready) }
  44.   mov  bl,ah
  45.   jmp  @done
  46.  
  47.   { take out the above two lines to make this just check
  48.     for disk ready/not ready }
  49.  
  50.   and  ah,$80
  51.   jz   @done   { error was something other than disk not ready }
  52.   mov  bl,false{ disk wasn't ready. store result }
  53.   @done:
  54.  
  55.   mov  ax,$0000  { reset drive }
  56.   INT  13H
  57.  
  58.   xor  ax,ax   { shut off disk drive quickly }
  59.   mov  es,ax
  60.   mov  ax,440h
  61.   mov  di,ax
  62.   mov  byte ptr es:[di],01h
  63.  
  64.   mov  al,bl   { retrieve result }
  65. end;  { diskstatus }
  66.  
  67.  
  68. function diskready(drive:CHAR):BOOLEAN; assembler;
  69. asm
  70.   cmp  drive,'a'
  71.   jb   @isupcase  { make it UPPER case }
  72.   sub  drive,20H
  73.   @isupcase:
  74.   cmp  drive,'Z'
  75.   jb   @driveok
  76.   mov  drive,'A'  { if drive isn't between 'A' and 'Z', make it A) }
  77.   @driveok:
  78.   mov  ax, seg buf
  79.   mov  es, ax
  80.   mov  bx, offset buf
  81.  
  82.   mov  ah, 02  { read disk sectors }
  83.   mov  al, 1   { number of sectors to transfer }
  84.   mov  ch, 1   { track number }
  85.   mov  cl, 1   { sector number }
  86.   mov  dh, 1   { head number }
  87.  
  88.   mov        dl, drive
  89.   sub        dl, 'A'     { subtract ORD of 'A' }
  90.  
  91.   {mov  dl, drive   { drive number (0=A, 3=C, or 80h=C, 81h=D) }
  92.   int  13h
  93.  
  94.   mov  bl,true { assume drive is ready }
  95.   and  ah,$80
  96.   jz   @done   { error was something other than disk not ready }
  97.   mov  bl,false{ disk wasn't ready. store result }
  98.   @done:
  99.  
  100.   mov  ax,$0000  { reset drive }
  101.   INT  13H
  102.  
  103.   xor  ax,ax   { shut off disk drive quickly }
  104.   mov  es,ax
  105.   mov  ax,440h
  106.   mov  di,ax
  107.   mov  byte ptr es:[di],01h
  108.  
  109.   mov  al,bl   { retrieve result }
  110. end;  { diskready }
  111.  
  112. BEGIN
  113. ClrScr;
  114. WriteLn(DiskStatus(0));
  115. WriteLn(DiskReady('a'));  { case ain't significant }
  116. readkey;
  117. END.